/*
 *    Copyright 2009-2010 The iBaGuice Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.google.code.ibaguice.samples;

import java.util.List;

import lombok.Setter;

import org.testng.annotations.Test;

import com.google.inject.Inject;

/**
 * 
 *
 * @author Simone Tripodi
 * @version $Id: SimpleTransactionalTestCase.java 329 2009-12-25 21:32:01Z simone.tripodi $
 */
public final class SimpleTransactionalServiceTestCase extends AbstractTestCase {

    @Inject
    @Setter
    private TransactionalService service;

    @Inject
    @Setter
    private TransactionalContactDao dao;

    @Override
    protected Class<? extends ContactDao> getDaoClass() {
        return TransactionalContactDao.class;
    }

    @Override
    protected Class<?>[] getMapperClass() {
        return new Class<?>[] { ContactMapper.class };
    }

    @Test
    public void testService() throws Exception {
        Contact modifiedContact = this.service.insertAndModifiedContact(this.getContact());
        assert (modifiedContact != null);
        assert modifiedContact.getFirstName().equals("Marco") : modifiedContact;
        assert modifiedContact.getLastName().equals("Speranza") : modifiedContact;
    }

    @Test(dependsOnMethods="testService")
    public void testServiceRetrieveInfo() throws Exception {
        this.service.insertAnagrafica();

        List<Contact> all = dao.getAll();
        assert all != null;
        assert all.size() == 11 : "Error on retrieve all contacts. Actual size: " + all.size();

        Contact retrievedContact = this.dao.selectById(3);
        assert(retrievedContact != null);
        assert retrievedContact.getFirstName().equals("Marco1") : retrievedContact;
        assert retrievedContact.getLastName().equals("Speranza1") : retrievedContact;
    }

}
